package com.muyu.system.domain.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.muyu.common.core.web.model.QueryModel;
import com.muyu.common.system.domain.SysLogininfor;
import com.muyu.system.domain.req.SysLogininforListReq;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.util.Date;

/**
 * 用户登录日志查询模型对象
 * @author dongzeliang
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class SysLogininforListModel extends QueryModel<SysLogininforListModel> {
    /**
     * 访问ID
     */
    private Long infoId;
    /**
     * IP地址
     */
    private String ipaddr;

    /**
     * 用户名称
     */
    private String userName;

    /**
     * 装填
     */
    private String status;

    /**
     * 开始时间
     */
    private Date beginTime;

    /**
     * 结束时间
     */
    private Date endTime;

    /**
     * 描述
     */
    private String msg;

    /**
     * 访问时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date accessTime;
    public static SysLogininforListModel reqBuild(SysLogininforListReq req){
        return SysLogininforListModel.builder()
                .ipaddr(req.getIpaddr())
                .userName(req.getUserName())
                .beginTime(req.getBeginTime())
                .endTime(req.getEndTime())
                .build()
                .domainBuild(req);
    }

    public static SysLogininforListModel buildSysLogininforListModel(SysLogininfor sysLogininfor) {
        return SysLogininforListModel.builder()
                .infoId(sysLogininfor.getInfoId())
                .ipaddr(sysLogininfor.getIpaddr())
                .userName(sysLogininfor.getUserName())
                .status(sysLogininfor.getStatus())
                .msg(sysLogininfor.getMsg())
                .accessTime(sysLogininfor.getAccessTime())
                .build();
    }
}
